home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 310_02 / ytab.c < prev    next >
Text File  |  1990-04-18  |  22KB  |  740 lines

  1. # define LITNUM 257
  2. # define LITFNUM 258
  3. # define LITCHAR 259
  4. # define LITSTR 260
  5. # define LITSYM 261
  6. # define CLASS 262
  7. # define ASSIGN 263
  8. # define BINARY 264
  9. # define PRIMITIVE 265
  10. # define NAMEDPRIM 266
  11. # define PSEUDO 267
  12. # define UPPERCASEVAR 268
  13. # define LOWERCASEVAR 269
  14. # define COLONVAR 270
  15. # define KEYWORD 271
  16. # define LP 272
  17. # define RP 273
  18. # define LB 274
  19. # define RB 275
  20. # define PERIOD 276
  21. # define BAR 277
  22. # define MBAR 278
  23. # define SEMI 279
  24. # define UPARROW 280
  25. # define PS 281
  26. # define MINUS 282
  27. # define PE 283
  28.  
  29. # line 26 "parser.y"
  30. # include "env.h"
  31. # include "drive.h"
  32. # include "parser.h"
  33.  
  34. # line 31 "parser.y"
  35. typedef union  {
  36.     struct litlist         *a;
  37.     struct blockstruct     *b;
  38.     char             *c;
  39.     struct exprstruct     *e;
  40.     int               i;
  41.     struct keylist         *k;
  42.     struct classstruct     *l;
  43.     struct methodstruct     *m;
  44.     struct objstruct     *o;
  45.     enum pseuvars          p;
  46.     struct primlist     *r;
  47.     struct statestruct     *s;
  48.     struct litstruct     *t;
  49.     struct primstruct     *u
  50.     } YYSTYPE;
  51.  
  52. # line 49 "parser.y"
  53. extern struct blockstruct *mkblock();
  54. extern struct classstruct *mkclass();
  55. extern struct varstruct *mkvar(), *addvlist(), *invlist();
  56. extern struct methodstruct *mkmethod();
  57. extern struct exprstruct *mkexpr(), *mkkey();
  58. extern struct keylist *mkklist();
  59. extern struct statestruct *mkstate();
  60. extern struct objstruct *mkobj();
  61. extern struct primstruct *mkprim();
  62. extern struct primlist *addprim();
  63. extern struct litstruct *mklit();
  64. extern struct litlist *addlit();
  65. extern char   *bincat();
  66.  
  67. struct varstruct *instvars;
  68. struct varstruct *contextvars;
  69.  
  70. int bytetop = 0;
  71. uchar bytearray[1000];
  72.  
  73. YYSTYPE e;
  74. int errorcount = 0;
  75. #define yyclearin yychar = -1
  76. #define yyerrok yyerrflag = 0
  77. extern int yychar;
  78. extern short yyerrflag;
  79. #ifndef YYMAXDEPTH
  80. #define YYMAXDEPTH 150
  81. #endif
  82. YYSTYPE yylval, yyval;
  83. # define YYERRCODE 256
  84.  
  85. # line 350 "parser.y"
  86.  
  87. # include <stdio.h>  
  88.  
  89. char *filename;
  90. FILE *fp;
  91. FILE *ofd;
  92.  
  93. # include "lexyy.c"
  94.  
  95. main(argc, argv) 
  96. int argc;
  97. char **argv;
  98. {    
  99.     if (argc != 2) quiter("parser: wrong number of arguments");
  100.     filename = argv[1];
  101.     fp = fopen(filename, "r");
  102.     if (fp == NULL) {
  103.         yerr("cannot open input file %s", filename);
  104.         quiter("parser quits");
  105.         }
  106.     ofd = stdout;
  107.     return(yyparse());
  108. }
  109.  
  110. quiter(s) char *s; {fprintf(stderr,"%s\n", s); exit(1);}
  111.  
  112. yywarn(s, v) char *s, *v; {
  113.    fprintf(stderr, "%s: line %d: Warning ", filename, linenum);
  114.    fprintf(stderr, s, v);
  115.    fprintf(stderr,"\n");
  116. }
  117.  
  118. yyerror(s) char *s; {yerr(s, "");}
  119.  
  120. yerr(s, v) 
  121. char *s, *v; 
  122. {
  123.    fprintf(stderr, "%s: line %d: ", filename, linenum);
  124.    fprintf(stderr, s, v);
  125.    fprintf(stderr,"\n");
  126.    if (errorcount++ > 10) quiter("too many errors, goodby");
  127. }
  128.  
  129. expect(str) char *str;
  130. {  char buffer[100];
  131.  
  132.    sprintf(buffer,"Expected %%s found %s", yytext);
  133.    yerr(buffer, str);
  134. }
  135.  
  136. int yywrap() { return(1);}
  137.  
  138. char *alloc(size) int size;      /* allocate a block of storage */
  139. {  char *p, *malloc();
  140.  
  141.    p = malloc( (unsigned) size);
  142.    if (p == (char *) 0) yyerror("out of free space");
  143.    return(p);
  144. }
  145.  
  146. char *bincat(s1, s2)
  147. char *s1, *s2;
  148. {    char *p;
  149.  
  150.     p = alloc(strlen(s1) + strlen(s2) + 1);
  151.     strcpy(p, s1);
  152.     strcat(p, s2);
  153.     return(p);
  154. }
  155. short yyexca[] ={
  156. -1, 1,
  157.     0, -1,
  158.     -2, 0,
  159.     };
  160. # define YYNPROD 120
  161. # define YYLAST 370
  162. short yyact[]={
  163.  
  164.   82,  80,  76,  77,  78, 129,  93,  25, 160, 155,
  165.  145, 126, 125, 128, 127, 133, 159, 144, 158,  36,
  166.   26,  90,  37,  28, 132, 134,  29,  82,  80,  76,
  167.   77,  78, 129, 152,  25, 150, 157, 109, 126, 125,
  168.  128, 127, 133, 122, 121, 116,  34,  26,  40, 107,
  169.   28, 132, 134,  29,  82,  80,  76,  77,  78,  15,
  170.   43,  48,  71,  72,  65,  14, 118,  32,  33,  67,
  171.  108,  73, 109,  42,  47,  99,  10,  35,  79,  81,
  172.  151,  82,  80,  76,  77,  78,  15, 100,  85,  71,
  173.   72,  65,  14, 118,   9,  92,  67,   6,  73, 111,
  174.  110, 147, 103,   5, 140,  79,  81, 136,  82,  80,
  175.   76,  77,  78,  15, 102,  13,  71,  72,  65,  14,
  176.   54,  15,  24,  67,  69,  73,  62,  14, 104,  17,
  177.  131, 142,  79,  81,  82,  80,  76,  77,  78,  15,
  178.   60,  53,  71,  72,  65,  14,  54,  45,  58,  67,
  179.   51,  73,   2, 146,   7,  70,  84,  52,  79,  81,
  180.   82,  80,  76,  77,  78,  15,  89,  49,  71,  72,
  181.   65,  14,  54,  94,  46,  67,  30,  73,  82,  80,
  182.   76,  77,  78,  15,  79,  81,  71,  72,  65,  14,
  183.  118,  22,  25,  67,  91,  73,  63,   4,   8,  25,
  184.   34,  12,  79,  81,  21,  26,  23,  25,  28, 101,
  185.   27,  29,  26,  85,  96,  28,  34,  27,  29,  95,
  186.   26,  32,  33,  28,  31,  27,  29, 124,  20,  88,
  187.    1, 137, 135,  97, 115,  41, 117,  32,  33, 120,
  188.  113, 114,  66,  39, 153, 119, 149, 141, 123,  64,
  189.  143, 139, 138,  50,  16,   3,  11,  20,  19,  44,
  190.   75, 105, 137,  83, 106, 148,  38,  61,  59,  57,
  191.   55,  87,  56,  18, 124,  74,  86,  68,   0,  98,
  192.    0, 154,   0,   0, 156,   0,   0,   0,   0,   0,
  193.    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
  194.    0,   0,   0,   0,   0,   0,   0,   0, 112,   0,
  195.    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
  196.    0,   0, 130,   0,   0,   0,   0,   0,   0,   0,
  197.    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
  198.    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
  199.    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
  200.    0,   0,   0,   0,   0,   0,   0,   0,   0, 130 };
  201. short yypact[]={
  202.  
  203. -159,-159,-1000,-180,-141,-1000,-1000,-1000, -65,-1000,
  204. -1000,-210,-193,-1000,-1000,-1000,-256,-1000,-210,-223,
  205. -196,-1000,-1000,-196, -72,-1000,-1000,-1000,-1000,-1000,
  206. -1000,-195,-1000,-1000,-1000,-1000,-1000, -65,-123,-181,
  207. -196,-1000,-1000,-1000,-1000,-1000, -40,-1000,-1000,-1000,
  208. -255,-1000, -97,-1000,-168,-273,-1000,-1000, -57, -57,
  209. -194,-182,-1000,-1000,-1000,-1000,-1000, -97,-1000,-1000,
  210. -1000,-155,-1000,-221,-1000,-1000,-1000,-1000,-1000,-202,
  211. -1000,-158,-1000, -56,-1000,-1000,-1000,-1000,-1000,-1000,
  212. -123,-1000, -97,-1000,-226, -79, -79,-226, -79,-1000,
  213. -1000,-229,-230,-1000,-176,-149,-260,-1000,-1000,-156,
  214. -1000,-1000,-1000,-1000,-1000,-1000, -79,-194,-1000, -72,
  215. -194,-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,
  216. -1000,-1000,-237,-1000,-158,-203,-1000,-1000,-242,-149,
  217. -1000,-267, -97,-1000,-1000,-1000,-239,-1000, -72,-257,
  218. -1000,-1000,-1000,-1000,-268,-1000,-1000,-1000,-1000,-1000,
  219. -1000 };
  220. short yypgo[]={
  221.  
  222.    0, 114, 277, 196, 219, 122, 275, 273, 272, 270,
  223.  148, 140, 269, 268, 267, 266, 264, 263, 261, 260,
  224.  258, 173, 256, 255, 129, 254, 126, 128, 253, 150,
  225.  141, 252, 251, 104, 250, 249, 124, 248, 242, 230,
  226.  152, 198, 197, 176, 224, 174, 166, 235, 156, 155,
  227.  153, 130 };
  228. short yyr1[]={
  229.  
  230.    0,  39,  39,  40,  41,  41,  23,  42,  42,  22,
  231.   22,  22,   3,   3,  43,  43,  45,  45,  45,  25,
  232.   25,  24,   7,   7,   7,   7,  20,  20,  47,  47,
  233.   15,  15,  44,  44,  44,  17,  17,  48,  28,  28,
  234.   46,  46,  29,  29,  30,  30,   9,   9,  12,  12,
  235.   13,  13,  14,  14,   8,   8,  21,  21,  10,  10,
  236.    4,   4,   5,   5,   5,   5,   5,  11,  11,  26,
  237.   26,  26,  26,  26,  26,  26,  38,  38,  27,  27,
  238.    2,  18,  18,  16,  16,  31,  31,  33,  33,  34,
  239.   34,  32,  32,  35,  35,  49,  36,  36,  36,  36,
  240.   36,  36,   6,   6,  19,  19,  37,  37,  37,  37,
  241.   37,  37,  37,  37,  51,  51,   1,   1,  50,  50 };
  242. short yyr2[]={
  243.  
  244.    0,   1,   2,   4,   1,   1,   3,   1,   1,   1,
  245.    2,   1,   1,   1,   0,   3,   1,   2,   1,   1,
  246.    3,   4,   1,   2,   1,   1,   2,   3,   1,   1,
  247.    0,   3,   1,   1,   1,   1,   2,   1,   1,   3,
  248.    0,   1,   2,   1,   3,   1,   1,   1,   1,   2,
  249.    1,   3,   2,   2,   1,   2,   2,   3,   1,   3,
  250.    1,   2,   1,   1,   1,   1,   1,   1,   2,   1,
  251.    1,   1,   1,   1,   3,   1,   4,   3,   0,   2,
  252.    4,   0,   2,   1,   2,   2,   1,   2,   1,   0,
  253.    1,   2,   3,   1,   3,   2,   1,   1,   1,   1,
  254.    1,   4,   1,   2,   1,   2,   1,   1,   1,   1,
  255.    1,   1,   1,   3,   2,   1,   0,   2,   1,   2 };
  256. short yychk[]={
  257.  
  258. -1000, -39, -40, -23, -42, 262, 256, -40, -41, 274,
  259.  256, -22,  -3, 256, 268, 262, -25, -24,  -7, -20,
  260.   -4, 269, 256, 271,  -5, 264, 277, 282, 280, 283,
  261.  -43, -44, 277, 278, 256, 270, 275, 278, -15, -44,
  262.  271, -47, 269, 256, -47,  -5, -45, 269, 256, -24,
  263.  -28, -29, 280, -30, 269,  -9,  -8, -12, -10, -13,
  264.